
package com.flowmodule.dao;
import com.flowmodule.bean.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import util.*;
public class TbFlowNodeDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbFlowNode tbFlowNode=null;
    private List<TbFlowNode> tbFlowNodeList=null;

    public boolean add(TbFlowNode inTbFlowNode){
        try{
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_FlowNode(FlowNodeName,UserId) values(?,?)";
        pt = conn.prepareStatement(sql);
        pt.setString(1,inTbFlowNode.getFlowNodeName());
        pt.setInt(2,inTbFlowNode.getUserId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public boolean del(int inFlowNodeId){
        return UtilDAO.del("Tb_FlowNode", "FlowNodeId", inFlowNodeId);
    }
    public boolean edit(TbFlowNode inTbFlowNode){
        try{
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_FlowNode set FlowNodeName=?,UserId=?,CreateTime=getdate() where FlowNodeId=?";
        pt = conn.prepareStatement(sql);
        pt.setString(1,inTbFlowNode.getFlowNodeName());
        pt.setInt(2,inTbFlowNode.getUserId());
        pt.setInt(3,inTbFlowNode.getFlowNodeId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public TbFlowNode getTbFlowNodeByFlowNodeId(int inFlowNodeId) {
        tbFlowNode=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowNode where FlowNodeId=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inFlowNodeId);
            rs = pt.executeQuery();
            while (rs.next()) {
                if (tbFlowNode == null)tbFlowNode = getTbFlowNode(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowNode;
    }
    public List<TbFlowNode> getTbFlowNodeAll() {
        tbFlowNodeList=new ArrayList<TbFlowNode>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowNode";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbFlowNodeList.add(getTbFlowNode(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowNodeList;
    }
    public List<TbFlowNode> getTbFlowNodeAll(VskPage vp) {
        tbFlowNodeList=new ArrayList<TbFlowNode>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowNode";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_FlowNode", "FlowNodeId"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbFlowNodeList.add(getTbFlowNode(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowNodeList;
    }
    public TbFlowNode getTbFlowNode(ResultSet rs) throws Exception{
        TbFlowNode tbFlowNode = new TbFlowNode();
        tbFlowNode.setFlowNodeId(rs.getInt("FlowNodeId"));
        tbFlowNode.setFlowNodeName(rs.getString("FlowNodeName"));
        tbFlowNode.setUserId(rs.getInt("UserId"));
        tbFlowNode.setCreateTime(rs.getString("CreateTime"));
        return tbFlowNode;
    }
}
